﻿using Common;
using DLL;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using SQLDLL;
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace NursingFormSystem.TubeDrawing
{
    public partial class AddExtubationRiskNursing : DevExpress.XtraEditors.XtraForm
    {
        #region 声明变量
        NursingFormRecord record = new NursingFormRecord();
        NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        int Sum = 0;
        PatientInfo Patientinfo;//选前选中患者信息
        Tb_User LoginUser;
        string Id = string.Empty;

        #endregion

        #region 窗体构造函数
        public AddExtubationRiskNursing(Tb_User loginUser, PatientInfo patientinfo, string Id)
        {
            InitializeComponent();
            //成员变量赋值
            this.Patientinfo = patientinfo;
            this.Id = Id;
            this.LoginUser = loginUser;

            //绑定数据
            BindInfo(Id);
            ElectronicSignature();
        }
        public AddExtubationRiskNursing(string[] loginUser, string[] patientinfo)
        {
            InitializeComponent();
            //成员变量赋值
            this.Patientinfo = ArrayToObject.ArrayToPatientInfo(patientinfo);
            this.Id = string.Empty;
            this.LoginUser = ArrayToObject.ArrayToLoginUser(loginUser);

            //绑定数据
            BindInfo(this.Id);
            ElectronicSignature();
        }
        public AddExtubationRiskNursing(string[] loginUser, string[] patientinfo, string Id)
        {
            InitializeComponent();
            //成员变量赋值
            this.Patientinfo = ArrayToObject.ArrayToPatientInfo(patientinfo);
            this.Id = Id;
            this.LoginUser = ArrayToObject.ArrayToLoginUser(loginUser);

            //绑定数据
            BindInfo(this.Id);
            ElectronicSignature();
        }
        /// <summary>
        /// 初始化加载印章图片
        /// </summary>
        private void ElectronicSignature()
        {
            ElectronicSignature es = new ElectronicSignature(LoginUser);
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, textzerenhushiqianming, picElectronicSignature, textzerenhushiqianming.Location);
        }
        #endregion

        #region 显示赋值
        private void BindInfo(string Id)
        {
            dateEditpingguriqi.DateTime = DateTime.Now;//默认显示当前日期 
            textzerenhushiqianming.Text = LoginUser.UserName;
            if (string.IsNullOrEmpty(Id)) return;
            string sql = "SELECT TOP 1 NursingFormData FROM NursingFormRecord(NOLOCK) WHERE Id='{0}'";
            sql = string.Format(sql, Id);
            DataTable tab = SqlHelper.ExecuteDataset(sql, System.Data.CommandType.Text).Tables[0];
            var NursingFormData = Convert.ToString(tab.Rows[0]["NursingFormData"]);
            Extubation bg = new Extubation();
            bg = XmlUtil.XMLToObject<Extubation>(NursingFormData, Encoding.UTF8);
            //年龄
            radioGroupnianling.SelectedIndex = Convert.ToInt32(bg.NianLin == "" ? "-1" : bg.NianLin);
            //意识
            radioGroupyishi.SelectedIndex = Convert.ToInt32(bg.YiShi == "" ? "-1" : bg.YiShi);
            //耐受程度
            radioGroupnaishouchengdu.SelectedIndex = Convert.ToInt32(bg.NaiShouChengDu == "" ? "-1" : bg.NaiShouChengDu);
            //活动
            radioGrouphuodong.SelectedIndex = Convert.ToInt32(bg.HuoDong == "" ? "-1" : bg.HuoDong);
            //疼痛
            radioGrouphezuochengdu.SelectedIndex = Convert.ToInt32(bg.HeCuoChengDu == "" ? "-1" : bg.HeCuoChengDu);
            //管道固定方式
            //单选改成多选 同时考虑原数据不能丢失解决方案
            if (!string.IsNullOrEmpty(bg.GuanDaoGuDingFangShi))
            {
                if (bg.GuanDaoGuDingFangShi.IndexOf('#') < 0 && bg.GuanDaoGuDingFangShi.Length == 1)
                {
                    switch (bg.GuanDaoGuDingFangShi)
                    {
                        case "0":
                            chkGuandaoGdfs1.Checked = true;
                            break;
                        case "1":
                            chkGuandaoGdfs2.Checked = true;
                            break;
                        case "2":
                            chkGuandaoGdfs3.Checked = true;
                            break;
                        default:
                            break;
                    }
                }

                if (bg.GuanDaoGuDingFangShi.IndexOf('#') > 0 && bg.GuanDaoGuDingFangShi.Split('#').Length == 3)
                {
                    chkGuandaoGdfs1.Checked = bg.GuanDaoGuDingFangShi.Split('#')[0].Equals("1");
                    chkGuandaoGdfs2.Checked = bg.GuanDaoGuDingFangShi.Split('#')[1].Equals("1");
                    chkGuandaoGdfs3.Checked = bg.GuanDaoGuDingFangShi.Split('#')[2].Equals("1");
                }
            }
            //总分
            textzongfen.Text = bg.ZongFen;
            //评估日期
            dateEditpingguriqi.Text = bg.PingGuRiQi;
            #region 管道种类--高危
            //管道种类--高危--气管
            string[] gdzl_gw = bg.GDZL_GaoWei.Split('#');
            if (gdzl_gw[0] == "0")
                checkEditqiguan.Checked = false;
            else
                checkEditqiguan.Checked = true;
            //管道种类--高危--胸导
            if (gdzl_gw[1] == "0")
                checkEditxiaongdao.Checked = false;
            else
                checkEditxiaongdao.Checked = true;
            //管道种类--高危--胸腔
            if (gdzl_gw[2] == "0")
                checkEditxiaongqiang.Checked = false;
            else
                checkEditxiaongqiang.Checked = true;
            //管道种类--高危--脑室
            if (gdzl_gw[3] == "0")
                checkEditnaoshi.Checked = false;
            else
                checkEditnaoshi.Checked = true;
            //管道种类--高危--前列
            if (gdzl_gw[4] == "0")
                checkEditqianlian.Checked = false;
            else
                checkEditqianlian.Checked = true;
            //管道种类--高危--吻合
            if (gdzl_gw[5] == "0")
                checkEditwenhe.Checked = false;
            else
                checkEditwenhe.Checked = true;
            //管道种类--高危--其他
            if (gdzl_gw[6] == "0")
                checkEditaita.Checked = false;
            else
                checkEditaita.Checked = true;
            #endregion
            #region 管道种类--中危
            //管道种类--中危--T管
            string[] gdzl_zw = bg.GDZL_ZhongWei.Split('#');
            if (gdzl_zw[0] == "0")
                checkEdittg.Checked = false;
            else
                checkEdittg.Checked = true;
            //管道种类--中危--胃肠
            if (gdzl_zw[1] == "0")
                checkEditweichang.Checked = false;
            else
                checkEditweichang.Checked = true;
            //管道种类--中危--深静
            if (gdzl_zw[2] == "0")
                checkEditshenjing.Checked = false;
            else
                checkEditshenjing.Checked = true;
            //管道种类--中危--picc
            if (gdzl_zw[3] == "0")
                checkEdit1picc.Checked = false;
            else
                checkEdit1picc.Checked = true;
            //管道种类--中危--伤口
            if (gdzl_zw[4] == "0")
                checkEdit1shanggan.Checked = false;
            else
                checkEdit1shanggan.Checked = true;
            //管道种类--中危--其他
            if (gdzl_zw[5] == "0")
                checkEdit1qitaz.Checked = false;
            else
                checkEdit1qitaz.Checked = true;
            #endregion
            #region 管道种类--低危
            //管道种类--低危--导尿
            string[] GDZL_DiWei = bg.GDZL_DiWei.Split('#');
            if (GDZL_DiWei[0] == "0")
                checkEditdaoniao.Checked = false;
            else
                checkEditdaoniao.Checked = true;
            //管道种类--低危--胃管
            if (GDZL_DiWei[1] == "0")
                checkEditweiguan.Checked = false;
            else
                checkEditweiguan.Checked = true;
            //管道种类--低危--其他
            if (GDZL_DiWei[2] == "0")
                checkEditqitaguan.Checked = false;
            else
                checkEditqitaguan.Checked = true;
            #endregion
            #region 管道种类--文本
            //高危
            string[] guandaogaowei = bg.GDZL_GaoWei_Text.Split('/');
            numericUpDownqiguan.Text = guandaogaowei[0];
            numericUpDownxiongdao.Text = guandaogaowei[1];
            numericUpDownxiongqiang.Text = guandaogaowei[2];
            numericUpDownnaoshi.Text = guandaogaowei[3];
            numericUpDownqianlei.Text = guandaogaowei[4];
            numericUpDownwenhe.Text = guandaogaowei[5];
            numericUpDownqitag.Text = guandaogaowei[6];
            //中危
            string[] guandaozhongwei = bg.GDZL_ZhongWei_Text.Split('/');
            numericUpDownTguan.Text = guandaozhongwei[0];
            numericUpDownweichjang.Text = guandaozhongwei[1];
            numericUpDownshenjing.Text = guandaozhongwei[2];
            numericUpDownpicc.Text = guandaozhongwei[3];
            numericUpDownshangkou.Text = guandaozhongwei[4];
            numericUpDownqitaz.Text = guandaozhongwei[5];
            //低危
            string[] guandaodiwei = bg.GDZL_DiWei_Text.Split('/');
            numericUpDowndaoniao.Text = guandaodiwei[0];
            numericUpDownweiguan.Text = guandaodiwei[1];
            numericUpDownqytad.Text = guandaodiwei[2];
            #endregion
            #region 护理措施
            //护理措施--评估
            string[] pinggu = bg.HuLiCuoShi.Split('#');
            if (pinggu[0] == "1")
                checkEditppinggu.Checked = true;
            else
                checkEditppinggu.Checked = false;
            //护理措施--管道
            if (pinggu[1] == "1")
                checkEditguandao.Checked = true;
            else
                checkEditguandao.Checked = false;
            //护理措施--做好
            if (pinggu[2] == "1")
                checkEditzuohao.Checked = true;
            else
                checkEditzuohao.Checked = false;
            //护理措施--给予
            if (pinggu[3] == "1")
                checkEditjiyu.Checked = true;
            else
                checkEditjiyu.Checked = false;
            //护理措施--实施
            if (pinggu[4] == "1")
                checkEditshishi.Checked = true;
            else
                checkEditshishi.Checked = false;
            //护理措施--对外
            if (pinggu[5] == "1")
                checkEditduiwai.Checked = true;
            else
                checkEditduiwai.Checked = false;
            //护理措施--及时
            if (pinggu[6] == "1")
                checkEditjishi.Checked = true;
            else
                checkEditjishi.Checked = false;
            //护理措施--告知
            if (pinggu[7] == "1")
                checkEditgaozhi.Checked = true;
            else
                checkEditgaozhi.Checked = false;
            //护理措施--其他
            if (pinggu[8] == "1")
                checkEditqita.Checked = true;
            else
                checkEditqita.Checked = false;
            #endregion
            //责任护士签字
            textzerenhushiqianming.Text = bg.ZheRenHuShiQianMing;

            checkEditsydgybc.Checked = bg.SuoYouDaoGuanYiBaChu == "1";
            txtsuoyoudaoguanyibachusj.EditValue = bg.SuoYouDaoGuanYiBaChuShiJian;
            checkEditdaiguanzhuanke.Checked = bg.DaiGuanZhuanKe == "1";
            txtdaiguanzhuankesj.EditValue = bg.DaiGuanZhuanKeShiJian;
            checkEditdiaguanzhuanyuan.Checked = bg.DaiGuanChuYuan == "1";
            txtdaiguanchuyuansj.EditValue = bg.DaiGuanChuYuanShiJian;
            //预防效果
            radioGroupyfxg.SelectedIndex = Convert.ToInt32(bg.YuFangXiaoGuo == "" ? "-1" : bg.YuFangXiaoGuo);
        }
        #endregion

        #region 取消
        private void btn_edit_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
        }
        #endregion

        #region 保存
        private void simpleButtonbaocun_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(dateEditpingguriqi.Text))
                dateEditpingguriqi.DateTime = DateTime.Now;

            Extubation bg = new Extubation();
            //评估日期
            bg.PingGuRiQi = dateEditpingguriqi.DateTime.ToString("yyyy-MM-dd HH:mm:ss");
            bg.NianLin = radioGroupnianling.EditValue + "";       //年龄
            bg.YiShi = radioGroupyishi.EditValue + "";           //意识
            bg.NaiShouChengDu = radioGroupnaishouchengdu.EditValue + "";         //耐受程度
            bg.HuoDong = radioGrouphuodong.EditValue + "";       //活动  
            bg.HeCuoChengDu = radioGrouphezuochengdu.EditValue + "";     //合作程度
            //管道固定方式
            bg.GuanDaoGuDingFangShi = (chkGuandaoGdfs1.Checked ? 1 : 0) + "#" + (chkGuandaoGdfs2.Checked ? 1 : 0) + "#" + (chkGuandaoGdfs3.Checked ? 1 : 0);
            //高危-气管
            int GaoWeiqiguan = 0;
            if (numericUpDownqiguan.Text == "")
                GaoWeiqiguan = 1;
            else
                GaoWeiqiguan = Convert.ToInt32(numericUpDownqiguan.Text);
            //
            int GaoWeixiaongdao = 0;
            if (numericUpDownxiongdao.Text == "")
                GaoWeixiaongdao = 1;
            else
                GaoWeixiaongdao = Convert.ToInt32(numericUpDownxiongdao.Text);
            //
            int GaoWeixingqiang = 0;
            if (numericUpDownxiongqiang.Text == "")
                GaoWeixingqiang = 1;
            else
                GaoWeixingqiang = Convert.ToInt32(numericUpDownxiongqiang.Text);
            //
            int GaoWeixiongshi = 0;
            if (numericUpDownnaoshi.Text == "")
                GaoWeixiongshi = 1;
            else
                GaoWeixiongshi = Convert.ToInt32(numericUpDownnaoshi.Text);
            //
            int GaoWeiqianlian = 0;
            if (numericUpDownqianlei.Text == "")
                GaoWeiqianlian = 1;
            else
                GaoWeiqianlian = Convert.ToInt32(numericUpDownqianlei.Text);
            //
            int GaoWeiwenhe = 0;
            if (numericUpDownwenhe.Text == "")
                GaoWeiwenhe = 1;
            else
                GaoWeiwenhe = Convert.ToInt32(numericUpDownwenhe.Text);
            //
            int GaoWeiqita = 0;
            if (numericUpDownqitag.Text == "")
                GaoWeiqita = 1;
            else
                GaoWeiqita = Convert.ToInt32(numericUpDownqitag.Text);

            //管道种类--高危
            bg.GDZL_GaoWei = (checkEditqiguan.Checked ? (GaoWeiqiguan * 3).ToString() : "0") + "#" + (checkEditxiaongdao.Checked ? (GaoWeixiaongdao * 3).ToString() : "0") + "#" + (checkEditxiaongqiang.Checked ? (GaoWeixingqiang * 3).ToString() : "0") + "#" +
                            (checkEditnaoshi.Checked ? (GaoWeixiongshi * 3).ToString() : "0") + "#" + (checkEditqianlian.Checked ? (GaoWeiqianlian * 3).ToString() : "0") + "#" + (checkEditwenhe.Checked ? (GaoWeiwenhe * 3).ToString() : "0") + "#" +
                            (checkEditaita.Checked ? (GaoWeiqita * 3).ToString() : "0");

            int GaoWeiTguan = 0;
            if (numericUpDownTguan.Text == "")
                GaoWeiTguan = 1;
            else
                GaoWeiTguan = Convert.ToInt32(numericUpDownTguan.Text);
            //
            int GaoWeiweichang = 0;
            if (numericUpDownweichjang.Text == "")
                GaoWeiweichang = 1;
            else
                GaoWeiweichang = Convert.ToInt32(numericUpDownweichjang.Text);
            //
            int GaoWeishenjing = 0;
            if (numericUpDownshenjing.Text == "")
                GaoWeishenjing = 1;
            else
                GaoWeishenjing = Convert.ToInt32(numericUpDownshenjing.Text);
            //
            int GaoWeipicc = 0;
            if (numericUpDownpicc.Text == "")
                GaoWeipicc = 1;
            else
                GaoWeipicc = Convert.ToInt32(numericUpDownpicc.Text);
            //
            int GaoWeishangkou = 0;
            if (numericUpDownshangkou.Text == "")
                GaoWeishangkou = 1;
            else
                GaoWeishangkou = Convert.ToInt32(numericUpDownshangkou.Text);
            //
            int GaoWeiqitaz = 0;
            if (numericUpDownqitaz.Text == "")
                GaoWeiqitaz = 1;
            else
                GaoWeiqitaz = Convert.ToInt32(numericUpDownqitaz.Text);

            //管道种类--中危
            bg.GDZL_ZhongWei = (checkEdittg.Checked ? (GaoWeiTguan * 2).ToString() : "0") + "#" + (checkEditweichang.Checked ? (GaoWeiweichang * 2).ToString() : "0") + "#" + (checkEditshenjing.Checked ? (GaoWeishenjing * 2).ToString() : "0") + "#" +
                            (checkEdit1picc.Checked ? (GaoWeipicc * 2).ToString() : "0") + "#" + (checkEdit1shanggan.Checked ? (GaoWeishangkou * 2).ToString() : "0") + "#" + (checkEdit1qitaz.Checked ? (GaoWeiqitaz * 2).ToString() : "0");

            //
            int GaoWeidaoniao = 0;
            if (numericUpDowndaoniao.Text == "")
                GaoWeidaoniao = 1;
            else
                GaoWeidaoniao = Convert.ToInt32(numericUpDowndaoniao.Text);
            //
            int GaoWeiweiguan = 0;
            if (numericUpDownweiguan.Text == "")
                GaoWeiweiguan = 1;
            else
                GaoWeiweiguan = Convert.ToInt32(numericUpDownweiguan.Text);
            //
            int GaoWeiqitad = 0;
            if (numericUpDownqytad.Text == "")
                GaoWeiqitad = 1;
            else
                GaoWeiqitad = Convert.ToInt32(numericUpDownqytad.Text);

            //管道种类--低危
            bg.GDZL_DiWei = (checkEditdaoniao.Checked ? (GaoWeidaoniao * 1).ToString() : "0") + "#" + (checkEditweiguan.Checked ? (GaoWeiweiguan * 1).ToString() : "0") + "#" + (checkEditqitaguan.Checked ? (GaoWeiqitad * 1).ToString() : "0");

            //管道种类--文本
            bg.GDZL_GaoWei_Text = (numericUpDownqiguan.Text) + "/" + (numericUpDownxiongdao.Text) + "/" + (numericUpDownxiongqiang.Text) + "/" + (numericUpDownnaoshi.Text) + "/" + (numericUpDownqianlei.Text) + "/" + (numericUpDownwenhe.Text) + "/" + (numericUpDownqitag.Text);
            bg.GDZL_ZhongWei_Text = (numericUpDownTguan.Text) + "/" + (numericUpDownweichjang.Text) + "/" + (numericUpDownshenjing.Text) + "/" + (numericUpDownpicc.Text) + "/" + (numericUpDownshangkou.Text) + "/" + (numericUpDownqitaz.Text);
            bg.GDZL_DiWei_Text = (numericUpDowndaoniao.Text) + "/" + (numericUpDownweiguan.Text) + "/" + (numericUpDownqytad.Text);

            //护理措施
            bg.HuLiCuoShi = (checkEditppinggu.Checked ? "1" : "0") + "#" + (checkEditguandao.Checked ? "1" : "0") + "#" + (checkEditzuohao.Checked ? "1" : "0") + "#" +
                            (checkEditjiyu.Checked ? "1" : "0") + "#" + (checkEditshishi.Checked ? "1" : "0") + "#" + (checkEditduiwai.Checked ? "1" : "0") + "#" +
                            (checkEditjishi.Checked ? "1" : "0") + "#" + (checkEditgaozhi.Checked ? "1" : "0") + "#" + (checkEditqita.Checked ? "1" : "0");

            //总分
            bg.ZongFen = textzongfen.Text;
            //表单ID
            bg.FormId = (int)FormType.Extubation;
            //表单名字
            bg.FormName = EnumHelper.GetDescription(FormType.Extubation);
            bg.SuoYouDaoGuanYiBaChu = checkEditsydgybc.Checked ? "1" : "0";
            bg.SuoYouDaoGuanYiBaChuShiJian = txtsuoyoudaoguanyibachusj.Text;
            bg.DaiGuanZhuanKe = checkEditdaiguanzhuanke.Checked ? "1" : "0";
            bg.DaiGuanZhuanKeShiJian = txtdaiguanzhuankesj.Text;
            bg.DaiGuanChuYuan = checkEditdiaguanzhuanyuan.Checked ? "1" : "0";
            bg.DaiGuanChuYuanShiJian = txtdaiguanchuyuansj.Text;
            bg.YuFangXiaoGuo = radioGroupyfxg.EditValue + "";    //预防效果
            //表单ID
            record.FormId = (int)FormType.Extubation;
            //表单名字
            record.FormName = EnumHelper.GetDescription(FormType.Extubation);
            //住院号
            record.PatientId = Patientinfo.PATIENT_ID;
            //住院次数
            record.VisitId = Patientinfo.VISIT_ID;
            //患者姓名
            record.PatientName = Patientinfo.PATIENT_NAME;
            //床号
            record.BedNo = Patientinfo.BED_NO;
            //当前患者科室ID
            record.DepartmentId = Patientinfo.DEPARTMENT_ID;
            //当前患者科室名称
            record.DepartmentName = Patientinfo.DEPARTMENT_NAME;
            //当前患者病区ID
            record.AreaId = Patientinfo.NURSE_CELL_CODE;
            //当前患者病区名称
            record.AreaName = Patientinfo.NURSE_CELL_NAME;
            //时间
            record.AssessmentDate = dateEditpingguriqi.DateTime;
            record.Id = Id == "" ? 0 : Convert.ToInt32(Id);
            if (string.IsNullOrEmpty(Id))
                bg.ZheRenHuShiQianMing = LoginUser.UserName;
            else
                bg.ZheRenHuShiQianMing = this.textzerenhushiqianming.Text;
            record.NursingFormData = XmlUtil.ObjectToXML(bg, Encoding.UTF8);
            var ret = formService.SetNursingFormRecord(Newtonsoft.Json.JsonConvert.SerializeObject(record));
            if (ret.Code == 1)
            {
                if (Base.ESSwitch.Equals("on"))//电签开始
                {
                    //TODO:电签接口提交
                    string extraInfo = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root><sign_sys>{0}</sign_sys><title>{1}</title><patient_id>{2}</patient_id><patient_name>{3}</patient_name><emr_id>{4}</emr_id><emr_catalog>{5}</emr_catalog><his_id>{6}</his_id><event_no>{7}</event_no><visit_number>{8}</visit_number><dept_name>{9}</dept_name><prescribe_number>{10}</prescribe_number><prescribe_sub_number>{11}</prescribe_sub_number><prescribe_operation>医嘱操作（发送、校对、停止、作废）或门诊处方操作（发送）</prescribe_operation><radiotherapy_id>放疗号</radiotherapy_id><process_name>CT定位申请单审核</process_name><process_time>CT定位申请单审核时间</process_time><extend_value_1>备用扩展1</extend_value_1><extend_value_2>备用扩展2</extend_value_2><extend_value_3>备用扩展3</extend_value_3><extend_value_4>备用扩展4</extend_value_4><extend_value_5>备用扩展5</extend_value_5><extend_value_6>备用扩展6</extend_value_6><extend_value_7>备用扩展7</extend_value_7><extend_value_8>备用扩展8</extend_value_8><extend_value_9>备用扩展9</extend_value_9></root>";
                    extraInfo = string.Format(extraInfo, EnumHelper.GetDescription(FormType.Extubation) + (record.Id > 0 ? "-更新" : "-新增"), EnumHelper.GetDescription(FormType.Extubation), record.PatientId, record.PatientName, record.Id, record.FormId, "", record.PatientId, record.VisitId, LoginUser.DepartmentName, record.PatientId, record.PatientId);
                    ElectronicSignature es = new ElectronicSignature(LoginUser);
                    bool flag = es.GetElectronicSignatureImage(es, record.NursingFormData, extraInfo, ((int)FormType.Extubation).ToString(), EnumHelper.GetDescription(FormType.Extubation), Patientinfo.PATIENT_ID, Patientinfo.VISIT_ID);
                    if (!flag) { MessageBox.Show("电子签名失败"); return; }
                }//电签结束

                MessageBox.Show(ret.M);
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show(ret.M);
            }
        }
        #endregion

        #region 计算总分
        public void SumTotal()
        {
            int Total = 0;
            int Total1 = 0;
            int Total2 = 0;
            int Total3 = 0;
            int Total4 = 0;
            int Total5 = 0;
            int Total6 = 0;
            int Total7 = 0;
            int Total8 = 0;
            int Total9 = 0;
            int Total10 = 0;
            int Total11 = 0;
            int Total12 = 0;
            int Total13 = 0;
            int Total14 = 0;
            int Total15 = 0;
            int Total16 = 0;
            int Total17 = 0;
            int Total18 = 0;
            int Total19 = 0;
            int Total20 = 0;
            int Total21 = 0;

            //年龄
            if (radioGroupnianling.SelectedIndex == 0)
                Total = 2;
            else if (radioGroupnianling.SelectedIndex == 1)
                Total = 2;
            else
                Total = 0;
            //意识
            if (radioGroupyishi.SelectedIndex == 0)
                Total1 = 3;
            else if (radioGroupyishi.SelectedIndex == 1)
                Total1 = 2;
            else if (radioGroupyishi.SelectedIndex == 2)
                Total1 = 1;
            else
                Total1 = 0;
            //耐受程度
            if (radioGroupnaishouchengdu.SelectedIndex == 0)
                Total2 = 3;
            else if (radioGroupnaishouchengdu.SelectedIndex == 1)
                Total2 = 2;
            else if (radioGroupnaishouchengdu.SelectedIndex == 2)
                Total2 = 1;
            else
                Total2 = 0;
            //活动
            if (radioGrouphuodong.SelectedIndex == 0)
                Total3 = 2;
            else if (radioGrouphuodong.SelectedIndex == 1)
                Total3 = 1;
            else
                Total3 = 0;
            //合作程度
            if (radioGrouphezuochengdu.SelectedIndex == 0)
                Total4 = 3;
            else if (radioGrouphezuochengdu.SelectedIndex == 1)
                Total4 = 2;
            else if (radioGrouphezuochengdu.SelectedIndex == 2)
                Total4 = 1;
            else
                Total4 = 0;
            //管道固定方式
            Total5 = 0;
            if (chkGuandaoGdfs1.Checked)
                Total5 += 3;
            if (chkGuandaoGdfs2.Checked)
                Total5 += 2;
            if (chkGuandaoGdfs3.Checked)
                Total5 += 1;
            //高危-气管
            if (checkEditqiguan.Checked)
            {
                if (numericUpDownqiguan.Text == "")
                    Total6 = 3;
                else
                    Total6 = Convert.ToInt32(numericUpDownqiguan.Text) * 3;
            }
            else
                Total6 = 0;
            //高危-胸导
            if (checkEditxiaongdao.Checked)
            {
                if (numericUpDownxiongdao.Text == "")
                    Total7 = 3;
                else
                    Total7 = Convert.ToInt32(numericUpDownxiongdao.Text) * 3;
            }
            else
                Total7 = 0;
            //高危-胸腔
            if (checkEditxiaongqiang.Checked)
            {
                if (numericUpDownxiongqiang.Text == "")
                    Total8 = 3;
                else
                    Total8 = Convert.ToInt32(numericUpDownxiongqiang.Text) * 3;
            }
            else
                Total8 = 0;
            //高危-脑室
            if (checkEditnaoshi.Checked)
            {
                if (numericUpDownnaoshi.Text == "")
                    Total9 = 3;
                else
                    Total9 = Convert.ToInt32(numericUpDownnaoshi.Text) * 3;
            }
            else
                Total9 = 0;
            //高危-前列
            if (checkEditqianlian.Checked)
            {
                if (numericUpDownqianlei.Text == "")
                    Total10 = 3;
                else
                    Total10 = Convert.ToInt32(numericUpDownqianlei.Text) * 3;
            }
            else
                Total10 = 0;
            //高危-吻合
            if (checkEditwenhe.Checked)
            {
                if (numericUpDownwenhe.Text == "")
                    Total11 = 3;
                else
                    Total11 = Convert.ToInt32(numericUpDownwenhe.Text) * 3;
            }
            else
                Total11 = 0;
            //高危-其他
            if (checkEditaita.Checked)
            {
                if (numericUpDownqitag.Text == "")
                    Total12 = 3;
                else
                    Total12 = Convert.ToInt32(numericUpDownqitag.Text) * 3;
            }
            else
                Total12 = 0;
            //中危-T管
            if (checkEdittg.Checked)
            {
                if (numericUpDownTguan.Text == "")
                    Total13 = 2;
                else
                    Total13 = Convert.ToInt32(numericUpDownTguan.Text) * 2;
            }
            else
                Total13 = 0;
            //中危-胃肠
            if (checkEditweichang.Checked)
            {
                if (numericUpDownweichjang.Text == "")
                    Total14 = 2;
                else
                    Total14 = Convert.ToInt32(numericUpDownweichjang.Text) * 2;
            }
            else
                Total14 = 0;
            //中危-深静
            if (checkEditshenjing.Checked)
            {
                if (numericUpDownshenjing.Text == "")
                    Total15 = 2;
                else
                    Total15 = Convert.ToInt32(numericUpDownshenjing.Text) * 2;
            }
            else
                Total15 = 0;
            //中危-picc
            if (checkEdit1picc.Checked)
            {
                if (numericUpDownpicc.Text == "")
                    Total16 = 2;
                else
                    Total16 = Convert.ToInt32(numericUpDownpicc.Text) * 2;
            }
            else
                Total16 = 0;
            //中危-伤口
            if (checkEdit1shanggan.Checked)
            {
                if (numericUpDownshangkou.Text == "")
                    Total17 = 2;
                else
                    Total17 = Convert.ToInt32(numericUpDownshangkou.Text) * 2;
            }
            else
                Total17 = 0;
            //中危-其他
            if (checkEdit1qitaz.Checked)
            {
                if (numericUpDownqitaz.Text == "")
                    Total18 = 2;
                else
                    Total18 = Convert.ToInt32(numericUpDownqitaz.Text) * 2;
            }
            else
                Total18 = 0;
            //低危-导尿
            if (checkEditdaoniao.Checked)
            {
                if (numericUpDowndaoniao.Text == "")
                    Total19 = 1;
                else
                    Total19 = Convert.ToInt32(numericUpDowndaoniao.Text) * 1;
            }
            else
                Total19 = 0;
            //低危-胃管
            if (checkEditweiguan.Checked)
            {
                if (numericUpDownweiguan.Text == "")
                    Total20 = 1;
                else
                    Total20 = Convert.ToInt32(numericUpDownweiguan.Text) * 1;
            }
            else
                Total20 = 0;
            //低危-其他
            if (checkEditqitaguan.Checked)
            {
                if (numericUpDownqytad.Text == "")
                    Total21 = 1;
                else
                    Total21 = Convert.ToInt32(numericUpDownqytad.Text) * 1;
            }
            else
                Total21 = 0;
            Sum = Total + Total1 + Total2 + Total3 + Total4 + Total5 + Total6 + Total7 + Total8 + Total9 + Total10 + Total11 + Total12 + Total13 + Total14 + Total15 + Total16 + Total17 + Total18 + Total19 + Total20 + Total21;
            textzongfen.Text = Sum.ToString();
        }
        #endregion

        #region Changed事件
        private void radioGroupnianling_SelectedIndexChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void radioGroupyishi_SelectedIndexChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void radioGrouphuodong_SelectedIndexChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void radioGroupqingxu_SelectedIndexChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void radioGrouptengtong_SelectedIndexChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void radioGroupgoutong_SelectedIndexChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        //文本框的值计算
        private void numericUpDownqiguan_EditValueChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void chkGuandaoGdfs1_CheckedChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void chkGuandaoGdfs2_CheckedChanged(object sender, EventArgs e)
        {
            SumTotal();
        }

        private void chkGuandaoGdfs3_CheckedChanged(object sender, EventArgs e)
        {
            SumTotal();
        }
        #endregion

        #region 管道种类文本框，默认0，勾选时值为1
        private void checkEditqiguan_CheckedChanged(object sender, EventArgs e)
        {
            //气管
            if (checkEditqiguan.Checked)
                numericUpDownqiguan.Text = "1";
            else
                numericUpDownqiguan.Text = "";
            SumTotal();
        }

        private void checkEditxiaongdao_CheckedChanged(object sender, EventArgs e)
        {
            //胸导
            if (checkEditxiaongdao.Checked)
                numericUpDownxiongdao.Text = "1";
            else
                numericUpDownxiongdao.Text = "";
            SumTotal();
        }

        private void checkEditxiaongqiang_CheckedChanged(object sender, EventArgs e)
        {
            //胸腔
            if (checkEditxiaongqiang.Checked)
                numericUpDownxiongqiang.Text = "1";
            else
                numericUpDownxiongqiang.Text = "";
            SumTotal();
        }

        private void checkEditnaoshi_CheckedChanged(object sender, EventArgs e)
        {
            //脑室
            if (checkEditnaoshi.Checked)
                numericUpDownnaoshi.Text = "1";
            else
                numericUpDownnaoshi.Text = "";
            SumTotal();
        }

        private void checkEditqianlian_CheckedChanged(object sender, EventArgs e)
        {
            //前列
            if (checkEditqianlian.Checked)
                numericUpDownqianlei.Text = "1";
            else
                numericUpDownqianlei.Text = "";
            SumTotal();
        }

        private void checkEditwenhe_CheckedChanged(object sender, EventArgs e)
        {
            //吻合
            if (checkEditwenhe.Checked)
                numericUpDownwenhe.Text = "1";
            else
                numericUpDownwenhe.Text = "";
            SumTotal();
        }

        private void checkEditaita_CheckedChanged(object sender, EventArgs e)
        {
            //其他--高危
            if (checkEditaita.Checked)
                numericUpDownqitag.Text = "1";
            else
                numericUpDownqitag.Text = "";
            SumTotal();
        }

        private void checkEdittg_CheckedChanged(object sender, EventArgs e)
        {
            //T管
            if (checkEdittg.Checked)
                numericUpDownTguan.Text = "1";
            else
                numericUpDownTguan.Text = "";
            SumTotal();
        }

        private void checkEditweichang_CheckedChanged(object sender, EventArgs e)
        {
            //胃肠
            if (checkEditweichang.Checked)
                numericUpDownweichjang.Text = "1";
            else
                numericUpDownweichjang.Text = "";
            SumTotal();
        }

        private void checkEditshenjing_CheckedChanged(object sender, EventArgs e)
        {
            //深静
            if (checkEditshenjing.Checked)
                numericUpDownshenjing.Text = "1";
            else
                numericUpDownshenjing.Text = "";
            SumTotal();
        }

        private void checkEdit1picc_CheckedChanged(object sender, EventArgs e)
        {
            //picc
            if (checkEdit1picc.Checked)
                numericUpDownpicc.Text = "1";
            else
                numericUpDownpicc.Text = "";
            SumTotal();
        }

        private void checkEdit1shanggan_CheckedChanged(object sender, EventArgs e)
        {
            //伤口
            if (checkEdit1shanggan.Checked)
                numericUpDownshangkou.Text = "1";
            else
                numericUpDownshangkou.Text = "";
            SumTotal();
        }

        private void checkEdit1qitaz_CheckedChanged(object sender, EventArgs e)
        {
            //其他-中危
            if (checkEdit1qitaz.Checked)
                numericUpDownqitaz.Text = "1";
            else
                numericUpDownqitaz.Text = "";
            SumTotal();
        }

        private void checkEditdaoniao_CheckedChanged(object sender, EventArgs e)
        {
            //导尿
            if (checkEditdaoniao.Checked)
                numericUpDowndaoniao.Text = "1";
            else
                numericUpDowndaoniao.Text = "";
            SumTotal();
        }

        private void checkEditweiguan_CheckedChanged(object sender, EventArgs e)
        {
            //胃管
            if (checkEditweiguan.Checked)
                numericUpDownweiguan.Text = "1";
            else
                numericUpDownweiguan.Text = "";
            SumTotal();
        }

        private void checkEditqitaguan_CheckedChanged(object sender, EventArgs e)
        {
            //其他-低危
            if (checkEditqitaguan.Checked)
                numericUpDownqytad.Text = "1";
            else
                numericUpDownqytad.Text = "";
            SumTotal();
        }
        #endregion

        #region 转归双击事件
        private void txtsuoyoudaoguanyibachusj_DoubleClick(object sender, EventArgs e)
        {
            txtsuoyoudaoguanyibachusj.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
        }

        private void txtdaiguanzhuankesj_DoubleClick(object sender, EventArgs e)
        {
            txtdaiguanzhuankesj.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
        }

        private void txtdaiguanchuyuansj_DoubleClick(object sender, EventArgs e)
        {
            txtdaiguanchuyuansj.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
        }
        #endregion
    }
}